<template>
	<view class="pb20">
		<navbar :title="i18n.drqb"></navbar>
		<view class="w690 auto white fsb py25">
			<text class="wp50 text--center" :class="{ 'color-theme': mode }" @click="Mode(true)">{{ i18n.zjc }}</text>
			<text class="wp50 text--center" :class="{ 'color-theme': !mode }" @click="Mode(false)">{{ i18n.sy }}</text>
		</view>
		<view class="w690 auto">
			<text class="f14 hui mt15 block auto">{{ mode ? i18n.drinput1 : i18n.drinput2 }}</text>
			<textarea
				type="text"
				value=""
				placeholder-class="color-gray"
				class="h294 bgcc border auto my15 white py15 w566 px15 f14"
				:placeholder="mode ? i18n.qsrzjc : i18n.qsrsy"
				maxlength="9999"
				v-model="Value"
			/>
		</view>
		<view class="">
			<text class="w690 f14 hui mt15 block auto">{{ i18n.qbmc }}</text>
			<input type="text" value="" class="w690 h96 bgcc border f14 auto index my15" placeholder-class="color-gray" :placeholder="i18n.qsrqbmc" v-model="walletName" maxlength="15" />
		</view>
		<view class="">
			<text class="w690 f14 hui mt15 block auto">{{ i18n.szaqmm }}</text>
			<view class="fcc auto bor10 mt15 py15 bgcc mx15 px15">
				<input :password="!eyestate" value="" class="flex-1 f14" :placeholder="i18n.qsraqmm" placeholder-class="color-gray" v-model="pws" maxlength="6"/>
				<image :src="eyestate?'../../static/login/eye1.png':'../../static/login/eye2.png'" @click="eyesin(0)"
					class="eyes"></image>
			</view>
			<view class="fcc auto bor10 mt10 py15 bgcc mx15 px15">
				<input :password="!comfirmstate" value="" class="flex-1 f14" :placeholder="i18n.qqraqmm" placeholder-class="color-gray" v-model="pwss" maxlength="6"/>
				<image :src="comfirmstate?'../../static/login/eye1.png':'../../static/login/eye2.png'" @click="eyesin(1)"
					class="eyes"></image>
			</view>
		</view>
		<view class="btn-blue block auto mt30 w690" @click="Login()">{{ i18n.ksdr }}</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			mode: true,
			Value: '',
			walletName: '',
			pws: '',
			pwss: '',
			eyestate:false,
			comfirmstate:false,
			otoken: ''
		};
	},
	onShow() {
		if(uni.getStorageSync('token'))this.otoken = uni.getStorageSync('token')
	},
	computed: {
		i18n() {
			return this.$t('login');
		}
	},
	methods: {
		Mode(value) {
			this.mode = value;
		},
		Login() {
			if (this.Value == '') {
				uni.showToast({
					title: this.mode ? this.$t('tips').zjctips : this.$t('tips').sytips,
					icon: 'none'
				});
				return false;
			}
			if (this.walletName == '') {
				uni.showToast({
					title: this.$t('tips').mctips,
					icon: 'none'
				});
				return false;
			}
			if (this.pws == '' || [...this.pws].length != 6 || !/^\d*$/.test(this.pws)) {
				uni.showToast({
					title: this.$t('tips').mmtips,
					icon: 'none'
				});
				return false;
			}
			if (this.pws != this.pwss) {
				uni.showToast({
					title: this.$t('tips').mmbyz,
					icon: 'none'
				});
				return false;
			}
			this.Sign();
		},
		async Sign() {
			let params = {
				phoneId: this.UID,
				walletName: this.walletName,
				passworld: this.pws,
				confirmPassworld: this.pwss,
				importType:this.mode?'memo':'priKey'
			};
			if(this.mode){
				params.memo = this.Value.split(' ').join(',')
			}else{
				params.priKey = this.Value
			}
			let { data } = await this.$http.post('login.importMemoOrPrikey', params, { isAuth: false, tipConfig: { isLoading: true } });
			uni.setStorageSync('token', data.token);
			uni.switchTab({
				url: '../index/index'
			});
			if (this.otoken) {
				uni.reLaunch({
					url:'../user/account'
				});
			} else {
				uni.setStorageSync('token', data.token);
				uni.switchTab({
					url: '../index/index'
				});
			}
		},
		eyesin(index){
			if(index==0){
				this.eyestate = !this.eyestate
			}else{
				this.comfirmstate = !this.comfirmstate
			}
		},
		getDeviceInfo(){
			let that = this
			plus.device.getInfo({
				success:function(e){
					that.UID = e.uuid
				},
				fail:function(e){
					that.UID = e.uuid
				}
			});
		}
	}
};
</script>

<style lang="less">
.h294 {
	height: 234rpx;
}
.w566 {
	width: 636rpx;
}
.eyes{
	width: 34rpx;
	height: 34rpx;
}
</style>
